<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
<title>配送转换</title>
<jsp:include page="../../include/header.jsp"></jsp:include>
<style type="text/css">
table th {
	text-align: center;
}

table td {
	text-align: center;
}

table {
	empty-cells: show;
	border-collapse: collapse;
	margin: 0 auto;
}

.col-lg-9 {
	width: 100%;
}

.pcc {
	width: 110px;
	height: 34px;
}

input {
	text-indent: 10px;
	border-radius: 5px;
}
/*排序 */
.querySort {
	position: relative;
}

.down {
	position: absolute;
	top: 12px;
	display: inline-block;
	width: 10px;
	height: 12px;
	margin-left: 8px;
	background: url("${BASE_PATH}/static/images/sprite-arrow.png") 0 61px;
}

.sort .querySort:NTH-OF-TYPE(2) .down {
	top: -3px;
	transform: rotateX(180deg);
}

.querySort:hover .down {
	background: url("${BASE_PATH}/static/images/sprite-arrow.png") 0 21px;
}

.downSort {
	position: absolute;
	top: 3px;
	left: 3px;
	width: 18px;
	height: 24px;
	opacity: 0;
	cursor: pointer;
}

.upSort {
	position: absolute;
	top: -15px;
	left: 3px;
	width: 18px;
	height: 24px;
	opacity: 0;
	cursor: pointer;
}
</style>
</head>
<body>
	<div id="wrapper" class="row">
		<div class="col-lg-12">
			<h1 class="page-header">配送转换</h1>
		</div>
		<!-- 添加隐藏域，传值用于判断 -->
		<%-- <input name="type" value="${type}" hidden="hidden"> --%>
	<!-- 搜索框 -->
	<div class="title-top col-lg-12">
		<label class="search-label">会员手机号：</label>
			<input type="text" id="sPhone" value="" placeholder="手机号" class="form-control search-input " style="width: 180px" maxlength="21">
		<label class="search-label">会员卡号：</label>
			<input type="text" id="sCard" value="" placeholder="请输入会员卡号" class="form-control search-input "style="width: 180px" maxlength="21">
		<label class="search-label">匹配状态：</label> 
				<select id="match" class="selectpicker pull-left p-l-5" data-width="12%">
					<option value="0">全部</option>
					<option value="1">已匹配</option>
					<option value="2">未匹配</option>
				</select>
		<div class="clearfix"></div>
		<label class="search-label">公司：</label>
		<div class="search-input">
        	<select name="sSeller" id="sSeller" class="form-control" style="width: 180px">
        		<c:if test="${fn:length(sellerList) > 0}">
        			<option value="">请选择公司</option>
        			<c:forEach items="${sellerList}" var="seller" varStatus="s">
							<option value="${seller.sellerId }">${seller.sellerName }</option>	
					</c:forEach>
        		</c:if>
        	</select>
        </div>
	    <label class="search-label">分公司：</label>
	    <div class="search-input">
        	<select name="sStore" id="sStore" class="form-control" >
        			<option value="">请选择分公司</option>
        	</select>
        </div>
	    <label class="search-label">营业部：</label>
	    <div class="search-input">
		    <select name="sDao" id="sDao" class="form-control" >
	        	<option value="">请选择营业部</option>
	        </select>
	    </div>
	    
	   		<button class="btn btn-success search-btn" onclick="query();">确定</button>
			<button class="btn btn-success search-btn" onclick="reset();">重置</button>
		<div class="clearfix"></div>
    	<label class="search-label">默认最新转换比例：</label>
    	<div class="search-input">
        	<select name="sNum" id="sNum" class="form-control"  disabled="disabled">
        		<c:if test="${fn:length(ListChangeScale) > 0}">
        			<c:forEach items="${ListChangeScale}" var="changeScale" varStatus="s">
							<option value="${changeScale.scaleValue}">${changeScale.scaleValue}</option>	
					</c:forEach>
        		</c:if>
        	</select>
        </div>
		<label class="search-label">转换类型：</label>
		<div class="search-input">
        	<select id="sType" class="selectpicker" data-width="150">
				<!-- <option value="1">积分</option>
				<option value="2">抵扣券</option> -->
				<option value="3">惠券</option>
			</select>
        </div>	
			<button class="btn btn-success margin-lf" onclick="toView();">预览</button>	
			<button class="btn btn-success  margin-lf" onclick="doDeliveryExcel();">配送</button>
			<shiro:hasPermission name="bus:user:jifen:doExcel">
				<button onclick="doExcel();" class="btn btn-success pull-right">导出</button>
			</shiro:hasPermission>
			
	</div>
		<div class="col-lg-12 title-top">
			<div class="col-lg-12">
				<div class="text-muted single-line-text pull-left">
					共 <font color="#428bca" id="dataCount">0</font> 条记录
				</div>

				<!-- <div style="float:right;margin-right: 30px;">
						<div class="text-muted single-line-text pull-right"> &nbsp;&nbsp;<input type="radio" class="radioItem" id="state1" name="state" value="1" />
						 	积分&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" class="radioItem" id="state2" name="state" value="2" />
						   抵扣券&nbsp;&nbsp; &nbsp;&nbsp;<input type="radio" class="radioItem" id="state3" name="state" value="3" />惠券</div>
					</div> -->
			</div>
			<div class="table-responsive panel panel-default">
				<table id="dataTable" class="table table-hover table-bordered"
					style="overflow: scroll;">
					<thead>
						<tr>
							<th width="50px;"></th>
							<th width="150px;">匹配编码</th>
							<th class="sort" width="100px;">电子券 
							<a class="querySort"><i class="down"></i> <input type="radio" class="downSort" name="state" value="4" onclick="query1(7)"/></a>
							<a class="querySort"><i class="down"></i> <input type="radio" class="upSort" name="state" value="2" onclick="query1(8)"></a>
							</th>
							<th width="150px;">会员卡号</th>
							<th width="150px;">会员姓名</th>
							<th width="150px;">会员手机号</th>
							<th width="150px;">所属分公司</th>
							<th width="100px;">营业部</th>
							<th width="150px;">办卡日期</th>
							<th class="sort" width="100px;">积分 
							<a class="querySort"> <i class="down"></i> <input type="radio" class="downSort" name="state" value="1" onclick="query1(1)"/></a>
							<a class="querySort"> <i class="down"></i> <input type="radio" name="state" value="2" class="upSort" onclick="query1(2)"></a>
							</th>
							<th class="sort" width="100px;">抵扣券
							<a class="querySort"><i class="down"></i><input type="radio" class="downSort" name="state" value="2" onclick="query1(3)"/></a> 
							<a class="querySort"> <i class="down"></i> <input type="radio" name="state" value="2" class="upSort" onclick="query1(4)"></a>
							</th>
							<th class="sort" width="100px;">惠券
							<a class="querySort"><i class="down"></i> <input type="radio" class="downSort" name="state" value="3" onclick="query1(5)"/></a>
							<a class="querySort"><i class="down"></i> <input type="radio" class="upSort" name="state" value="2" onclick="query1(6)"></a>
							</th>
							<th width="100px;">积分明细</th>
						</tr>
					</thead>
					<tbody id="dataList"></tbody>
				</table>
			</div>
			<div class="col-lg-12">
				<ul id="dataPagination" class="pagination-sm pull-right"></ul>
			</div>
		</div>

	</div>
	<jsp:include page="../../include/javascripts.jsp"></jsp:include>
	<!-- 异步加载下一页数据后，用模板渲染 -->
	<script type="text/html" id="dataTpl">
		{{each list as item}}
				 <tr id="item{{item.id}}" data-id="{{item.id}}">
					<td><input type="checkbox" name="check_name" value="{{item.phone}}" style="height:20px;"></td>
					<td>{{item.clientCode}}</td>
					<td>
						{{if item.ecoupon}}{{item.ecoupon}}{{/if}}
						{{if !item.ecoupon}}0{{/if}}
					</td>
				 	<td>
						<a href="javascript:showUserDetail('{{item.id}}');"><font color="#40a9ff" id="dataCount">{{if item.card}}{{item.card }}{{/if}}
								{{if !item.card}}--{{/if}}
							</font>
						</a>
					</td>
					<td>{{item.name}}</td>
					<td>{{item.phone}}</td>
					<td>
						{{if item.toBossTwoId}}{{item.title}}{{/if}}
						{{if !item.toBossTwoId}}--{{/if}}
					</td>
					<td>
						{{if item.toBossOneId}}{{item.trueName}}{{/if}}
						{{if !item.toBossOneId}}--{{/if}}
					</td>
					<td>{{item.createDate}}</td>
					<td>{{item.sppoint}}</td>
					<td>{{item.jkpoint}}</td>
					<td>{{item.jypoint}}</td>
					<td>
						<a href="javascript:showUser('{{item.id}}');"><span class="btn">积分明细</span></a>
					</td>
				</tr>
		{{/each}}
</script>
	<script type="text/javascript">

var dataPaginator;
$(query);
function query(){
	 var phone=$("#sPhone").val(),card=$("#sCard").val(),seller=$("#sSeller").val(),store=$("#sStore").val(),dao=$("#sDao").val(),match=$("#match").val();
	 var params = {
		pageSize:10,
		phone:phone,
		seller:seller,
		store:store,
		dao:dao,
		card:card,
		match:match
	};
	if(dataPaginator){
		dataPaginator.destroy();
	}
	dataPaginator = Kit.pagination("#dataPagination","${BASE_PATH}/change/delivery/page",params,function(result){
		//设置显示最新的数据数量
		$("#dataCount").html(result.object.totalRow);
		//根据模板渲染数据并填充
		$("#dataList").empty().append(template("dataTpl",result.object));
	});
}
/* 重置查询条件 */
function reset(){
	$("#sPhone").val("");
	$("#sCard").val("");
	$("#sSeller").val("");$("#sSeller").trigger("change");
	$("#sStore").val("");$("#sStore").trigger("change");
	$("#sDao").val("");$("#sDao").trigger("change");
	
}


/**
 * 此排序与默认排序冲突故分成二方法
 */
function query1(index){
	 var phone=$("#sPhone").val(),card=$("#sCard").val(),seller=$("#sSeller").val(),store=$("#sStore").val(),dao=$("#sDao").val(),match=$("#match").val();
	 var params = {
		pageSize:10,
		phone:phone,
		card:card,
		seller:seller,
		store:store,
		dao:dao,
		index:index,
		match:match
	};
	if(dataPaginator){
		dataPaginator.destroy();
	}
	dataPaginator = Kit.pagination("#dataPagination","${BASE_PATH}/change/delivery/page1",params,function(result){
		//设置显示最新的数据数量
		$("#dataCount").html(result.object.totalRow);
		//根据模板渲染数据并填充
		$("#dataList").empty().append(template("dataTpl",result.object));
	});
}

//跳转页面
var showDialog;
function showUser(id){
	showDialog = Kit.dialog("会员积分详情信息","${BASE_PATH}/bus/user/detailVip/"+id,{size:'size-wide',closable:true}).open();
}
var showDialog;
function showUserDetail(id){
	showDialog = Kit.dialog("会员详情信息","${BASE_PATH}/bus/user/detail/"+id,{size:'size-wide',closable:true}).open();
}
/*转换预览*/
var viewDialog;
function toView(){
	var adIds = "";
    $("input:checkbox[name=check_name]:checked").each(function(i){  
        if(i==0){  
            adIds = $(this).val();  
        }else{  
            adIds += (","+$(this).val());  
        }  
    }); 
    var num=$("#sNum").val(),type=$("#sType").val();
   
    if(adIds == ""){
    	Kit.alert("请选择要转换的人员");
    }else if(num == '' || num == undefined || num == null){
    	Kit.alert("请录入转换比例");
    }else{
    	viewDialog = Kit.dialog("转换预览","${BASE_PATH}/change/delivery/toView?adIds="+adIds+"&num="+num+"&type="+type,{size:'size-wide',closable:true}).open();
    }
}
/* 重置查询条件 */
function reset(){
	$("#sNum").val("");
	$("#sType").val("");$("#sType").trigger("change");
}
function onEditSuccess(newObject){
	$("#item"+newObject.id).replaceWith(template("dataTpl",{"list":[newObject]}));
}
function doExcel(){
	 var phone=$("#sPhone").val(),card=$("#sCard").val(),store=$("#sStore").val();
	window.location.href="${BASE_PATH}/change/delivery/doExcel?phone="+phone+"&card="+card+"&store="+store;
}
function doDeliveryExcel(){
	Kit.alert("未同步会员、无电子券会员将跳过,无法导出");
	var adIds = "";
    $("input:checkbox[name=check_name]:checked").each(function(i){  
        if(i==0){  
            adIds = $(this).val();  
        }else{  
            adIds += (","+$(this).val());  
        }  
    }); 
    var num=$("#sNum").val(),type=$("#sType").val();
   
    if(adIds == ""){
    	Kit.alert("请选择要转换的人员");
    }else if(num == '' || num == undefined || num == null){
    	Kit.alert("请录入转换比例");
    }else{
    	
    	window.location.href="${BASE_PATH}/change/delivery/doDeliveryExcel?adIds="+adIds+"&num="+num+"&type="+type;
    }
} 
//订单量、收藏量、浏览量  单选图片点击切换
var querySort=document.getElementsByClassName("querySort");//点击区域
var down=document.getElementsByClassName("down");
for(var i=0;i<querySort.length;i++){
	   //给每个class添加id标识(当索引)区分每个class
	   querySort[i].id=i;	   
	   //鼠标点击改变背景图片偏移
	   querySort[i].onclick=function(){
		   //当前索引
		   var index=this.id;
		   for( j=0;j<down.length;j++){
			   down[j].style.backgroundPosition="0px 61px";
		   }
		 //改变索引为当前的class背景图片偏移位置
		   down[index].style.backgroundPosition="0px 21px";
	   }
}
//异步取分公司的值
$("#sSeller").change(function(){
	sSeller=$("#sSeller").val();
	  $.ajax({
           type: "POST",
           url: "${BASE_PATH}/change/delivery/chooseStore",
           data: {"seller" : sSeller},
           dataType: "json",
           traditional: true,
           success: function(data){
			$("#sStore").empty(); 
			$("#sStore").append("<option value=''>请选择分公司</option>");
			for(var i=0; i<data.object.length;i++){
				$("#sStore").append("<option value='"+data.object[i].storeid+"'>"+data.object[i].title+"</option>");
               }
              // $("#toBossOneId").selectpicker("refresh");	
           }
       });
    });
$("#sStore").change(function(){
	sStore=$("#sStore").val();
	  $.ajax({
           type: "POST",
           url: "${BASE_PATH}/change/delivery/chooseDao",
           data: {"store" : sStore},
           dataType: "json",
           traditional: true,
           success: function(data){
          	   $("#sDao").empty(); 
               $("#sDao").append("<option value=''>请选择营业部</option>");
               for(var i=0; i<data.object.length;i++){
              	 $("#sDao").append("<option value='"+data.object[i].trueName+"'>"+data.object[i].trueName+"</option>");
               }
              	//$("#sDao").selectpicker("refresh");
           }
       });
    });
 /* 选择需要转换的会员 */
/* var toViewDialog;
function toView(){
	var adIds = "";  
    $("input:checkbox[name=check_name]:checked").each(function(i){  
        if(i==0){  
            adIds = $(this).val();  
        }else{  
            adIds += (","+$(this).val());  
        }  
    }); 
    if(adIds==""){
    	Kit.alert("请选择要转换的人员");
    }else{
  		 messageDialog=Kit.dialog("转换预览","${BASE_PATH}/change/delivery/toView/"+adIds,{size:'size-wide',closable:true}).open();
    }
} */

 
</script>
</body>
</html>